package cn.qiao.mdc.cglib;

import net.sf.cglib.proxy.Enhancer;

@SuppressWarnings("unchecked")
public class MDCProxyFactory {

    public static <T> T create(Class<T> targetType) {
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(targetType);
        enhancer.setCallback(new MDCInterceptor(null));
        return (T) enhancer.create();
    }

    public static <T> T create(Object target) {
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(target.getClass());
        enhancer.setCallback(new MDCInterceptor(target));
        return (T) enhancer.create();
    }
}
